package com.hl.shifangzhiyu.mapper;

import com.hl.shifangzhiyu.pojo.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    @Select("SELECT id, nickname, phone, password, province, city, points FROM user WHERE phone = #{phone}")
    User findByPhone(@Param("phone") String phone);

    @Insert("INSERT INTO user (nickname, phone, password, province, city, points) VALUES (#{nickname}, #{phone}, #{password}, #{province}, #{city}, #{points})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(User user);

    // 根据 ID 获取用户信息
    @Select("SELECT id, nickname, password, phone, city, province, points FROM user WHERE id = #{id}")
    User getUserById(@Param("id") Integer id);

    // 更新用户信息
    @Update("UPDATE user SET nickname = #{nickname}, city = #{city}, province = #{province} WHERE id = #{id}")
    int updateUser(User user);
    @Select("SELECT * FROM user WHERE id = #{id}")
    User selectById(@Param("id") Integer id);

    @Update("UPDATE user SET password = #{password} WHERE id = #{id}")
    int updatePassword(@Param("id") Integer id, @Param("password") String password);
}
